/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef HILOG_WRAPPER_H
#define HILOG_WRAPPER_H

#define CONFIG_HILOG
#ifdef CONFIG_HILOG
#include "hilog/log.h"
namespace OHOS {
namespace Msdp {
#define __FILENAME__            (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#define __FORMATED(fmt, ...)    "[%{public}s] %{public}s# " fmt, __FILENAME__, __FUNCTION__, ##__VA_ARGS__

#ifdef SPATIAL_LOGF
#undef SPATIAL_LOGF
#endif

#ifdef SPATIAL_LOGE
#undef SPATIAL_LOGE
#endif

#ifdef SPATIAL_LOGW
#undef SPATIAL_LOGW
#endif

#ifdef SPATIAL_LOGI
#undef SPATIAL_LOGI
#endif

#ifdef SPATIAL_LOGB
#undef SPATIAL_LOGB
#endif

// param of log interface, such as SPATIAL_LOGF.
enum SpatialAwarenessModule {
    MODULE_JS_NAPI = 0,
    MODULE_INNERKIT,
    MODULE_SERVICE,
    MODULE_JAVAKIT,
    MODULE_JNI,
    MODULE_ALGORITHM,
    MODULE_COMMON,
    MODULE_BUTT,
};

// 0xD002240: subsystem:msdp module:SpatialAwareness, reserved 8 bit.
static constexpr unsigned int BASE_SPATIAL_AWARENESS_DOMAIN_ID = 0xD002240;

enum SpatialAwarenessDomainId {
    JS_NAPI_DOMAIN = BASE_SPATIAL_AWARENESS_DOMAIN_ID + MODULE_JS_NAPI,
    INNERKIT_DOMAIN,
    SERVICE_DOMAIN,
    JAVAKIT_DOMAIN,
    ALGORITHM_DIMAIN,
    COMMON_DOMAIN,
    BUTT_DOMAIN
};

static constexpr OHOS::HiviewDFX::HiLogLabel SPATIAL_AWARENESS_MGR_LABEL[MODULE_BUTT] = {
    {LOG_CORE, JS_NAPI_DOMAIN, "SpatialAwarenessJsNapi"},
    {LOG_CORE, INNERKIT_DOMAIN, "SpatialAwarenessInnerkit"},
    {LOG_CORE, SERVICE_DOMAIN, "SpatialAwarenessService"},
    {LOG_CORE, JAVAKIT_DOMAIN, "SpatialAwarenessJava"},
    {LOG_CORE, COMMON_DOMAIN, "SpatialAwarenessCommon"},
    {LOG_CORE, ALGORITHM_DIMAIN, "SpatialAwarenessAlgorithm"},
};

// In order to improve performance, do not check the module range.
#define SPATIAL_LOGF(module, ...) \
    (void)OHOS::HiviewDFX::HiLog::Fatal(SPATIAL_AWARENESS_MGR_LABEL[module], __FORMATED(__VA_ARGS__))
#define SPATIAL_LOGE(module, ...) \
    (void)OHOS::HiviewDFX::HiLog::Error(SPATIAL_AWARENESS_MGR_LABEL[module], __FORMATED(__VA_ARGS__))
#define SPATIAL_LOGW(module, ...) \
    (void)OHOS::HiviewDFX::HiLog::Warn(SPATIAL_AWARENESS_MGR_LABEL[module], __FORMATED(__VA_ARGS__))
#define SPATIAL_LOGI(module, ...) \
    (void)OHOS::HiviewDFX::HiLog::Info(SPATIAL_AWARENESS_MGR_LABEL[module], __FORMATED(__VA_ARGS__))
#define SPATIAL_LOGB(module, ...) \
    (void)OHOS::HiviewDFX::HiLog::Debug(SPATIAL_AWARENESS_MGR_LABEL[module], __FORMATED(__VA_ARGS__))
} // namespace Msdp
} // namespace OHOS

#else

#define SPATIAL_LOGF(...)
#define SPATIAL_LOGE(...)
#define SPATIAL_LOGW(...)
#define SPATIAL_LOGI(...)
#define SPATIAL_LOGB(...)

#endif // CONFIG_HILOG

#endif // HILOG_WRAPPER_H
